package website.digitalocean.chapter14;

/**
 * @Author: 582895699@qq.com
 * @Desctription:
 * @Date: Created in 2023/2/13 22:44
 */
public class Dollar10Dispenser implements DispenseChain{

    protected DispenseChain dispenseChain;



    @Override
    public void sendNextChain(DispenseChain dispenseChain) {
        this.dispenseChain = dispenseChain;
    }

    @Override
    public void dispense(Currency currency) {
        int amount = currency.getAmount();
        if (amount >= 10) {
            int num = amount / 10;
            int remainder = amount % 10;
            System.out.println("Dispensing " + num + " 10$ note");
            if (remainder != 0) {
                this.dispenseChain.dispense(new Currency(remainder));
            } else {
                System.out.println("Amount should be in multiple of 10s.");
            }
        }
    }
}
